package com.zhijian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhijian.entity.ChatMessage;
import com.zhijian.mapper.ChatMessageMapper;
import com.zhijian.service.IChatMessageService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements IChatMessageService {

    @Override
    public List<ChatMessage> getOfflineMessages(String userId) {
        return this.list(new QueryWrapper<ChatMessage>()
                .eq("to_user_id", userId)
                .eq("status", 0)
                .orderByAsc("send_time"));
    }

    @Override
    public void markMessageAsRead(Long messageId) {
        ChatMessage message = this.getById(messageId);
        if (message != null) {
            message.setStatus(1);
            this.updateById(message);
        }
    }

    @Override
    public void saveMessage(ChatMessage message) {
        this.save(message);
    }
} 